﻿@{
    Layout = null;
}
<script type="text/javascript">
    $(function () {
        $("#rptUserList").datagrid({
            url: "User/List?r=" + Math.random(),
            onRowContextMenu: function (e, rowindex, rowData) {
                $("#rptUserList").datagrid('selectRow', rowindex);
                e.preventDefault();
                var row = $("#rptUserList").datagrid('getSelected');
                if (row) {
                    $('#menuUser').menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                }

            }

        });
    });
    function Delete() {
        var row = $("#rptUserList").datagrid('getSelected');
        if (row) {
            $.messager.confirm('提醒', '<br>确定要删除' + row.LoginName + '这个用户吗?', function (r) {
                if (r) {
                    form1.action = "User/Delete/" + row.UserId;
                    $('#loading').window('open');
                    $("#form1").ajaxSubmit({ action: this.action, method: this.method });
                }
            });
        } else {
            $.messager.alert('错误', '<br>请先选择要删除的数据！', 'error');
        }
    }
    function Edit() {
        var row = $("#rptUserList").datagrid('getSelected');
        if (row) {
            TreeLink('User/Edit/'+row.UserId, '用户编辑');
        } else {
            $.messager.alert('错误', '<br>请先选择要编辑的数据！', 'error');
        }
    }
    function RequestError() {
        $.messager.alert('错误', '<br>请求失败！', 'error');
    }
    function Search() {
        $("#rptUserList").datagrid({
            url: "User/List?UserName=" + escape($.trim($("#UserName").val())) + "&UserLoginName=" + escape($.trim($("#UserLoginName").val())) + "&r=" + Math.random(),
            pageNumber: 1
        }).datagrid('reload');
    }
    function formatSex(val,row) {
        if (val == "1") {
            return "男";
        }
        else {
            return "女";        
        }
    }
    function Detail() {
        var row = $("#rptUserList").datagrid('getSelected');
        if (row) {
            $('#UserDetail').window('open').panel({
                href: 'User/Detail/' + row.UserId+"?r="+Math.random()
            });
            //TreeLink('User/Detail/' + row.UserId, '用户编辑');
        } else {
            $.messager.alert('错误', '<br>请先选择要查看的数据！', 'error');
        }
    }
</script>
<form id="form1" action="User/Delete" method="post" data-ajax-failure="RequestError" data-ajax="true">
<div style="padding: 10px;">
    <table id="rptUserList" class="easyui-datagrid" width="100%" cache="false" title="Load Data"
        singleselect="true" toolbar="#tb" iconcls="icon-save" rownumbers="true" pagination="true"
        pagelist="[10,20,25,30]">
        <thead>
            <tr>
                <th field="UserId" width="50" align="center" hidden="true">
                    ID
                </th>
                <th field="LoginName" width="100">
                    登录账号
                </th>
                <th field="UserName" width="100">
                    用户名称
                </th>
                <th field="Sex" width="40" align="center" formatter="formatSex">
                    性别
                </th>
                <th field="Mobile" width="100" align="center">
                    手机号码
                </th>
                <th field="Address" width="250">
                    地址
                </th>
                <th field="Email" width="150">
                    Email
                </th>
                
                <th field="CreateTime" width="120" align="center">
                    创建时间
                </th>
            </tr>
        </thead>
    </table>
</div>
<div id="tb" style="height: auto">
    <div style="padding: 5px; height: 26px;">
        <a href="javascript:TreeLink('User/Create','新增用户')" class="easyui-linkbutton" style="float: left;"
            iconcls="icon-add" plain="true">新增</a>
        <div class="dialog-tool-separator">
        </div>
        <a href="javascript:void(0)" onclick="Edit();" class="easyui-linkbutton" style="float: left;"
            iconcls="icon-edit" plain="true">编辑</a>
        <div class="dialog-tool-separator">
        </div>
        <a href="javascript:void(0);" class="easyui-linkbutton" style="float: left;" iconcls="icon-cut"
            plain="true" onclick="javascript:Delete();">删除</a>
        <div class="dialog-tool-separator">
        </div>
        <a href="javascript:void(0);" class="easyui-linkbutton" style="float: left;" iconcls="icon-search"
            plain="true" onclick="javascript:Search();">查找</a>
    </div>
    <div style="border-top: 1px solid #CCCCCC; padding: 5px;">
        登录账号:
        <input id="UserLoginName" />
        用户名称:
        <input id="UserName" />
        <a href="javascript:Search();" class="easyui-linkbutton" iconcls="icon-search">Search</a>
    </div>
</div>
<div id="menuUser" class="easyui-menu" style="width: 120px;">
    <div iconcls="icon-edit" onclick="javascript:Edit();">
        编辑</div>
    <div class="menu-sep">
    </div>
    <div iconcls="icon-remove" onclick="javascript:Delete()">
        删除</div>
    <div class="menu-sep">
    </div>
    <div iconcls="icon-tip" onclick="javascript:Detail()">
        查看</div>
</div>
<div id="UserDetail" class="easyui-window" resizable="false" title="用户详情" minimizable="false" cache="false"
    modal="true" closed="true" dosize="false" collapsible="false" maximizable="false"
     style="width: 500px; height: 400px; padding-top: 10px; text-align: center;">
   
</div>
</form>
